package com.fs.groupSeven.service.impl;

import com.fs.groupSeven.Dao.TeachingInformationDao;
import com.fs.groupSeven.pojo.*;
import com.fs.groupSeven.service.TeachingInformationService;
import com.fs.groupSeven.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @description:
 * @author: st
 * @createDate: 2020/10/9
 * @version: 1.0
 */

@Service
public class TeachingInformationServiceImpl implements TeachingInformationService {

    @Autowired
    private TeachingInformationDao teachingInformationDao;

    @Override
    public List<TeachingInformation> getAllByClassName(String classname) {
        return teachingInformationDao.queryAllByClassName(classname);
    }

    @Override
    public List<TeachingInformation> getAllByClassName2(String classname) {
        return teachingInformationDao.queryAllByClassName2(classname);
    }

    @Override
    public TeachingInformation getAllByCode(String code) {
        return teachingInformationDao.queryOneByCode(code);
    }

    @Override
    public List<MyTeacherTest> getAllBySubjectId(Integer sid) {
        return teachingInformationDao.queryAllBySubjectId(sid);
    }

    @Override
    public List<MyClassRoomTest> getClassRoom() {
        return teachingInformationDao.queryClassRoom();
    }

    @Override
    public List<MySubjectTest> getSubject(Integer college_id) {
        return teachingInformationDao.querySubject(college_id);
    }

    @Override
    public String getClassRoomByClassId(Integer class_id) {
        return teachingInformationDao.queryClassRoomByClassId(class_id);
    }

    @Override
    public String getSubjectBySid(Integer subject_id) {
        return teachingInformationDao.querySubjectBySid(subject_id);
    }

    @Override
    public List<String> getClassName() {
        return teachingInformationDao.queryClassName();
    }

    @Override
    public boolean modifySubject(String oldName,String name,String duration) {
        int result = teachingInformationDao.updateBySubject(oldName,name,duration);
        return result > 0;
    }

    @Override
    public boolean modifySchedule(String time_on, String time_off, String identifier) {
        int result = teachingInformationDao.updateBySchedule(time_on,time_off,identifier);
        return result > 0;
    }

    @Override
    public boolean modifyClassroom(Integer class_id, Integer classroom_id) {
        int result = teachingInformationDao.updateByClassroom(class_id,classroom_id);
        return result > 0;
    }

    @Override
    public boolean modifyOldClassroom(Integer classroom_id) {
        int result = teachingInformationDao.updateByOldClassroom(classroom_id);
        return result > 0;
    }

    @Override
    public boolean deleteClassSubject(Integer class_id, Integer subject_id) {
        int result = teachingInformationDao.deleteClassSubject(class_id,subject_id);
        return result > 0;
    }

    @Override
    public boolean deleteSchedule(Integer class_id, Integer subject_id) {
        int result = teachingInformationDao.deleteSchedule(class_id,subject_id);
        return result > 0;
    }

    @Override
    public boolean insertClassSubject(Integer class_id, Integer subject_id) {
        int result = teachingInformationDao.insertClassSubject(class_id,subject_id);
        return result > 0;
    }

    @Override
    public boolean insertSchedule(Integer class_id, Integer subject_id,String time_on, String time_off, String identifier) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date d1 = null;
        java.util.Date d2 = null;
        try {
            d1 = format.parse(time_on);
            d2 = format.parse(time_off);
        } catch (Exception e) {
            e.printStackTrace();
        }
        java.sql.Date date1 = new java.sql.Date(d1.getTime());
        java.sql.Date date2 = new java.sql.Date(d2.getTime());

        int result = teachingInformationDao.insertSchedule(class_id,subject_id,date1,date2,identifier);
        return result > 0;
    }
}
